window.reliers.push("angularFileUpload");
corpApp.controller('controller',['$scope', '$modal', 'upserve','reference', 'ngDialog','$upload', function($scope, $modal, upserve,reference, ngDialog, $upload, $http){

	//资金来源
	$scope.Sources = [];
	$scope.getSources = function(){
		$scope.Sources=[{
			"SourceCode":"1",
			"SourceName":"成品油税"
		},
		{
			"SourceCode":"2",
			"SourceName":"营业税"
		},
		{
			"SourceCode":"3",
			"SourceName":"教育收入"
		}]
	};
	$scope.getSources();
	//项目类别
	$scope.ProjectSorts = [];
	$scope.getProjectSorts = function(){
		$scope.ProjectSorts=[{
			"ProjectSortCode":"1",
			"ProjectSortName":"日常养护费"
		},
		{
			"ProjectSortCode":"2",
			"ProjectSortName":"改建费"
		},
		{
			"ProjectSortCode":"3",
			"ProjectSortName":"建造费"
		}]
	};
	$scope.getProjectSorts();
	
	
	//科目代码参照
	$scope.showSubjectCodeSelectDlg = function(){
		
		var dialog = ngDialog.open({
			templateUrl: $path$ + "/public/template/Help_Subject_Conditionfilter.html",
			width:650,
			scope:$scope,
			controller:['$scope', 'upserve', function($scope, upserve){
				$scope.data = {};
				$scope.grid = {};
				
				$scope.columns = [
                    {field:'SubjectCode',title:'科目代码',width:100 , hidden:false},
				 	{field:'SubjectName ',title:'科目代码名称',width:100 , hidden:false}
				];
				
				$scope.options = {
				 	resizable:true,
				 	sortable: true,
				 	selectable:true,
				 	height: 300,
				 	pageable:true,
				 	groupable:false,
				 	columns:$scope.columns,
				 	change:function(){
				 		$scope.data = this.dataItem(this.select()[0]);
				 	},
				 	dataBound:function(e){
				 		var grid = this;
				 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
				 			$scope.ok();
				 		});
				 	}
				 };
				
				 $scope.dataSource = new kendo.data.DataSource({
				 	data:[],
				 	page: 1,
				 	pageSize:window.refPageSize
				});
				 $scope.subject=[{
					 "SubjectCode":"1",
					 "SubjectName":"城市公园建设"
				 },
				 {
					 "SubjectCode":"2",
					 "SubjectName":"道路桥梁支出"
				 },
				 {
					 "SubjectCode":"3",
					 "SubjectName":"公路运输支出"
				 }]
				 $scope.dataSource.data($scope.subject);
				 $scope.ok = function(){
					 $scope.setSubjectName($scope.data.SubjectName);
					 dialog.close();
				 }
				 $scope.cancel = function(){
					 dialog.close();
				 }
			}]
		});
	}
	//管理机构
	//科目代码参照
	$scope.showManagerCodeSelectDlg = function(){
		var dialog = ngDialog.open({
			templateUrl: $path$ + "/public/template/Help_Manager_Conditionfilter.html",
			width:650,
			scope:$scope,
			controller:['$scope', 'upserve', function($scope, upserve){
				$scope.data = {};
				$scope.grid = {};
				
				$scope.columns = [
                    {field:'ManagerCode',title:'管理机构代码',width:100 , hidden:false},
				 	{field:'ManagerName ',title:'管理机构名称',width:100 , hidden:false}
				];
				
				$scope.options = {
				 	resizable:true,
				 	sortable: true,
				 	selectable:true,
				 	height: 300,
				 	pageable:true,
				 	groupable:false,
				 	columns:$scope.columns,
				 	change:function(){
				 		$scope.data = this.dataItem(this.select()[0]);
				 	},
				 	dataBound:function(e){
				 		var grid = this;
				 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
				 			$scope.ok();
				 		});
				 	}
				 };
				
				 $scope.dataSource = new kendo.data.DataSource({
				 	data:[],
				 	page: 1,
				 	pageSize:window.refPageSize
				});
				 $scope.subject=[{
					 "ManagerCode":"1",
					 "ManagerName":"税务局"
				 },
				 {
					 "ManagerCode":"2",
					 "ManagerName":"交通局"
				 },
				 {
					 "ManagerCode":"3",
					 "ManagerName":"环保局"
				 }]
				 $scope.dataSource.data($scope.subject);
				 $scope.ok = function(){
					 $scope.setManagerName($scope.data.ManagerName)
					 dialog.close();
				 }
				 $scope.cancel = function(){
					 dialog.close();
				 }
			}]
		});
	}
	
	$scope.setManagerName = function(data){
		$scope.ManagerName = data; 
		$scope.$apply();
	}
	
	$scope.setSubjectName = function(data){
		$scope.SubjectName = data; 
		$scope.$apply();
	}
}]);